"""
 encoding    : utf-8
 @File       : daibanshiwupage.py
 @Author     : qin
 @Version    :
 @Description:
 @Date       : 2024/06/19
"""
import time

from common.logincommon import LoginCommon
from common.commonfunctions import Common
from selenium.webdriver.support.select import Select

class DaiBanShiWu(LoginCommon):
    def oprate_web(self):
        self.driver.switch_to.default_content()
        #定位并点击代办按钮
        # self.driver.find_element('xpath','/html/body/div[2]/div/div[1]/table/tbody/tr[14]/td/a/img').click()
        Common.getElement(self.driver,'xpath','/html/body/div[2]/div/div[1]/table/tbody/tr[14]/td/a/img').click()
        # 切换到第一层frame
        frame_ele = Common.getElement(self.driver, 'id', 'iframe_main')
        self.driver.switch_to.frame(frame_ele)
        #切换到第二层
        frame_ele = Common.getElement(self.driver,'xpath','/html/frameset/frame[1]')
        self.driver.switch_to.frame(frame_ele)
        #定位代办复选款并点击
        Common.getElement(self.driver,'xpath','/html/body/form[1]/div[2]/div/div[1]/div[2]/table/tbody/tr[1]/td[1]/div/input').click()

    def zhuanfaxietong(self):
        self.driver.switch_to.default_content()
        # 切换到第一层frame
        frame_ele = Common.getElement(self.driver, 'id', 'iframe_main')
        self.driver.switch_to.frame(frame_ele)
        #切换到第二层frame
        frame_ele = Common.getElement(self.driver, 'xpath','/html/frameset/frame[1]')
        self.driver.switch_to.frame(frame_ele)
        #定位转发协同按钮并点击
        Common.getElement(self.driver,'xpath','/html/body/form[1]/div[1]/div[1]/button').click()
        # 切换到做外层
        self.driver.switch_to.default_content()
        #切换到第一层表单
        frame_ele = Common.getElement(self.driver, 'xpath','/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/iframe')
        self.driver.switch_to.frame(frame_ele)
        #定位管理部按钮并点击
        Common.getElement(self.driver,'id','DeptTreeDiv_3_span').click()
        #定位选择按钮元素
        select_ele = Common.getElement(self.driver,'id','list1')
        select_obj = Select(select_ele)
        #定位选择张三元素
        select_obj.select_by_index(1)
        #定位添加按钮
        Common.getElement(self.driver,'xpath','/html/body/div[6]/button[2]').click()
        #定位确定并点击
        Common.getElement(self.driver,'xpath','/html/body/div[11]/button[1]').click()


    def zhuanfayoujian(self):
        pass

    def furuxietong(self):
        '''还未完成'''
        self.driver.switch_to.default_content()
        # 切换到第一层frame
        frame_ele = Common.getElement(self.driver, 'id', 'iframe_main')
        self.driver.switch_to.frame(frame_ele)
        #切换到第二层frame
        frame_ele = Common.getElement(self.driver, 'xpath', '/html/frameset/frame[1]')
        self.driver.switch_to.frame(frame_ele)
        #定位协同按钮并点击
        Common.getElement(self.driver,'xpath', '/html/body/form[1]/div[1]/div[3]/button').click()
        #返回到上一层frame
        self.driver.switch_to.parent_frame()
        #定位标题并输入内容
        Common.getElement(self.driver,'id', 'subject').send_keys('代办测试标题')
        #定位添加新流程


    def guidang(self):
        self.driver.switch_to.default_content()
        # 切换到第一层frame
        frame_ele = Common.getElement(self.driver, 'id', 'iframe_main')
        self.driver.switch_to.frame(frame_ele)
        # 切换到第二层frame
        frame_ele = Common.getElement(self.driver, 'xpath', '/html/frameset/frame[1]')
        self.driver.switch_to.frame(frame_ele)
        #定位归档按钮并点击
        Common.getElement(self.driver,'xpath', '/html/body/form[1]/div[1]/div[4]/button').click()
        #切换到最外层
        self.driver.switch_to.default_content()
        #切换到第一层frame
        frame_ele = Common.getElement(self.driver, 'xpath','/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/iframe')
        self.driver.switch_to.frame(frame_ele)
        #定位我的文档并点击
        Common.getElement(self.driver,'id', 'zTreeDiv_1_span').click()
        #定位确定按钮并点击
        Common.getElement(self.driver,'id', 'button_save').click()


    def check_zhuanfa(self,check_content):
        self.driver.switch_to.default_content()
        #定位转发成功文本
        text = Common.getElement(self.driver,'xpath','/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]').text
        assert text == check_content,'测试失败！'

    def check_youjian(self):
        pass

    def check_furu(self):
        pass

    def check_guidang(self,content):
        self.driver.switch_to.default_content()
        #定位归档成功的文本信息
        test = Common.getElement(self.driver,'xpath','/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]').text
        #定位确定按钮并点击
        Common.getElement(self.driver,'xpath','/html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[3]/td/div/input').click()
        assert test == content,'测试失败！'
